#include "jost/Object.hpp"
#include <iostream>

jost::Object::Object() throw()  : jost::Value(jost::Value::OBJECT) { }

jost::Object::~Object() throw() {
  ValueMap_t::iterator iter = this->field_map_.begin();
  ValueMap_t::iterator end = this->field_map_.end();
  
  while (iter != end){
      delete (iter->second);
      ++iter;
  }
  
}


std::string
jost::Object::serialize() throw() {
  ValueMap_t::iterator index = this->field_map_.begin();
  ValueMap_t::iterator end = this->field_map_.end();
  
  std::string s = "{";

  if (this->field_map_.size() != 0) {
      end--;
      while (index != (end)) {
          s += "\"" + index->first + "\":" + index->second->serialize() + ',';
          index++;
      }
      s += "\"" + index->first + "\":" + index->second->serialize();
  }
  
  s += "}";
  return s;
}
